home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / SOUND.SWG / 0002_ProAudio Spectrum Mixer Unit.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  10.6 KB  |  370 lines

  1. {--Title:       MVFUNCT.PAS
  2.    Author:      Patrick O'Malley AKA Silicom Slim
  3.    Constact:    e-mail: d005530c@dcfreenet.seflin.lib.fl.us
  4.    Language:    Turbo Pascal v6.0
  5.    Description: Functions and procedures to interface with the ProAudio
  6.                 Spectrum's mixer and volume controls.
  7.    Status:      Public Domain
  8.  
  9.   This unit is a primer for programming the ProAudio Spectum basic or 16, it
  10. doesn't seem to matter.
  11.   IMPORTANT TECH NOTE: All settings are in percent! Just a decimal from 0 to
  12. 100. Very odd. And sometimes when you set a volume too low, it will just go
  13. to 0. Basically what you enter will result in a volume +-2 percentage points
  14. off what you entered. Doesn't make much difference.
  15.   I have no idea what CrossChannels are. Or the FMSplitChips thing. They don't
  16. seem too interesting anyhow.
  17.   For the unknowing, mixers and volumes are basically the same thing. Setting
  18. the output of a mixer changes it's volume if you play something that uses
  19. that mixer. For example, a cd-rom drive is attached to the internal mixer
  20. input. The volume functions aren't really just for volumes anyhow. They
  21. control the treble, bass, loudness & enhanced switches too.
  22.   Most of the procedures and functions are simple to understand. The
  23. GetFunctionTable procedure is used internally by the unit.
  24.  
  25.   I'd like to request code re:SoundBlaster mixer/vol stuff. --}
  26.  
  27. Unit MVFunct;
  28.  
  29. interface
  30.  
  31. CONST
  32. {--volume channel select constants--}
  33. {--These constants are used _only_ with the functions/procedures that use a
  34.    call to functiontable.mvset(or get)volumefunction.
  35.     VolMute is strange. It appears in the COMMON.INC file of the PAS-SDK
  36.    but is never explained and doesn't seem to have an effect.
  37.     VolLoudEnh is also odd. It is supposed to be used to set the Loudness
  38.    and Enhanced switches (and it does). The only problem is that using
  39.    a value of 100% turns _both_ on. Doing a 0% turns off only enhanced then.
  40.    Maybe there is some trick I haven't discovered.
  41.     VolBass & VolTreble set the Bass and Treble.
  42.     VolLeft and VolRight are the master volume settings.
  43.     VolMode is some sort of modal setting. No documentation in the PAS-SDK.--}
  44.  
  45. VolMute    = $40;
  46. VolLoudEnh = $41;
  47. VolBass    = $42;
  48. VolTreble  = $43;
  49. VolLeft    = $44;
  50. VolRight   = $45;
  51. VolMode    = $46;
  52.  
  53. {--mixer selection constants--}
  54. {--These constants are used when a mixer can either be an input of output
  55.    mixer. For example, the internal connector (hooked to the cd-rom drive)
  56.    can either output sound or input it. So you can select the levels at
  57.    which it does these. For outputting sound levels use pmOUTPUTMIXER. --}
  58. pmOUTPUTMIXER = $00;
  59. pmINPUTMIXER  = $20;
  60.  
  61. {--left channel selection values--}
  62. {--these constants are used to select which mixer (they are: internal which
  63.    is usually the CD-ROM, external which _can_ be attached to external music
  64.    equiptment, microphone, PCM or digital sound, the internal speaker which
  65.    is re-routed by the pro-audio out it's speakers and the sound-blaster
  66.    emulation mixer. I have no idea what R_ or L_IMIXER is.--}
  67. L_FM = $01;
  68. L_IMIXER = $02;
  69. L_EXT = $03;
  70. L_INT = $04;
  71. L_MIC = $05;
  72. L_PCM = $06;
  73. L_SPEAKER = $07;
  74. L_FREE = $00;
  75. L_SBDAC = $00;
  76.  
  77. {--right channel selection values--}
  78. {--these constants can be used in places that ask for the channel to, for
  79.    example, change the setting of. they are for the right channel only. --}
  80. R_FM = $08;
  81. R_IMIXER = $09;
  82. R_EXT = $0A;
  83. R_INT = $0B;
  84. R_MIC = $0C;
  85. R_PCM = $0D;
  86. R_SPEAKER = $0E;
  87. R_FREE = $0F;
  88. R_SBDAC = $0F;
  89.  
  90. {--The following is used for the get/set, on/off procedures--}
  91. Get = True;
  92. Set_ = False;
  93. On = true;
  94. Off = false;
  95.  
  96.  
  97. Type tFunctionTable = record
  98.                         MVSetMixerFunction,
  99.                         MVSetVolumeFunction,
  100.                         MVSetFilterFunction,
  101.                         MVSetCrossChannel,
  102.                         MVGetMixerFunction,
  103.                         MVGetVolumeFunction,
  104.                         MVGetFilterFunction,
  105.                         MVGetCrossChannel,
  106.                         MVRealSoundSwitch,
  107.                         MVFMSplitSwitch     : Pointer;
  108.                       end;
  109. Var FunctionTable : tFunctionTable;
  110.  
  111.  
  112. Function IsMVSOUNDInstalled : Boolean;
  113. Procedure GetFunctionTable;             {internal, used by MVFUNCT.TPU}
  114. Procedure SetMasterVolume(R,L : Boolean;R_Setting,L_Setting : Word);
  115. Procedure SetMixer(In_Out, Channel_Select : Byte; Mixer_Setting : Word);
  116. Procedure GetMasterVolume(R,L : Boolean; Var R_Setting, L_Setting : Word);
  117. Function GetMixer(In_Out, Channel_Select : Word) : Byte;
  118. Procedure SetFilter(Filter_Setting : Byte);
  119. Function GetFilter : Byte;
  120. Procedure Get_Set_RealSound(Get_Set : Boolean;Var On_Off : boolean);
  121. Procedure SetVolume(Channel,Setting : Word);
  122. Function GetVolume(Channel : Word) : Byte;
  123. Function GetIRQ : Byte;
  124. Function GetDMA : Byte;
  125.  
  126. implementation
  127.  
  128. Function IsMVSOUNDInstalled : Boolean;
  129. {Basically this function checks for MVSOUND.SYS, the device driver that is
  130.  required to do the mixer functions that follow. Simple. }
  131. Var edx : Word;
  132. Begin
  133.   IsMVSOUNDInstalled := FALSE;
  134.   asm
  135.     mov  ax, 0bc00h
  136.     mov  bx, 03f3fh
  137.     xor  cx, cx
  138.     xor  dx, dx
  139.     int  2fh
  140.     xor  cx, bx
  141.     xor  dx, cx
  142.     mov  [edx], dx
  143.   end;
  144.   if edx = $4d56 then IsMVSOUNDInstalled := True
  145.   else IsMVSOUNDInstalled := False;
  146. End;    {IsMVSOUNDInstalled func}
  147.  
  148. Procedure GetFunctionTable;          {used by the unit}
  149. Var FTableSeg, FTableOfs : Word;
  150. Begin
  151.   Asm
  152.     mov  ax, 0bc03h
  153.     int  2fh
  154.     mov  [ftableofs], bx        {function table offset}
  155.     mov  [ftableseg], dx        {function table segment}
  156.   end;
  157.   {--Move the table into the function table of pointers for pascal--}
  158.  
  159. Move(Mem[ftableseg:ftableofs],Mem[seg(functiontable):ofs(functiontable)],40);
  160. End; {GetFunctionTable proc}
  161.  
  162. Procedure SetMasterVolume(R,L : Boolean;R_Setting,L_Setting : Word);
  163. {This procedure is actually the SetVolume procedure but is master volume
  164.  channel specific.
  165.  Vars R&L : Boolean tell it which channel (right or left) to change.
  166.  R_&L_Setting are the % (0-100) to set the channel to.
  167. }
  168. Begin
  169.   If R then begin
  170.   asm
  171.     mov  bx, R_Setting
  172.     mov  cx, VolRight
  173.     {$F+}
  174.     call functiontable.mvsetvolumefunction
  175.     {$F-}
  176.   end;
  177.   end;
  178.   if L then begin
  179.   asm
  180.     mov  bx, L_Setting
  181.     mov  cx, VolLeft
  182.     {$F+}
  183.     call functiontable.mvsetvolumefunction
  184.     {$F-}
  185.   end;
  186.   end;
  187. End; {setmastervolume func}
  188.  
  189. Procedure SetMixer(In_Out, Channel_Select : Byte; Mixer_Setting : Word);
  190. { This procedure is used to set the I/O volume of one of the mixers.
  191.   In_Out is a constant listed above under mixer selection constants.
  192.   Channel_Select is either the right or left constant from the list above
  193.   under channel selection values.
  194.   Mixer_Setting is the % (0-100) to set the volume to.
  195. }
  196. Begin
  197.   Asm
  198.     mov  bx, Mixer_Setting
  199.     xor  cx, cx
  200.     xor  dx, dx
  201.     mov  cl, In_Out
  202.     mov  dl, Channel_Select
  203.     {$F+}
  204.     call functiontable.MVSetMixerFunction
  205.     {$F-}
  206.   End;
  207. End;    {setmixer proc}
  208.  
  209. Procedure GetMasterVolume(R,L : Boolean; Var R_Setting, L_Setting : Word);
  210. { See SetMaster volume for the variable descriptions.
  211.   Basically returns the current master volume.
  212. }
  213. Var Temp : Word;
  214. Begin
  215.   If R then Begin
  216.   Asm
  217.     mov  cx, VolRight
  218.     {$F+}
  219.     call functiontable.mvgetvolumefunction
  220.     {$F-}
  221.     mov  [Temp], bx
  222.   end;
  223.   R_Setting := Temp;
  224.   end;
  225.   If L then Begin
  226.   asm
  227.     mov  cx, VolLeft
  228.     {$F+}
  229.     call functiontable.mvgetvolumefunction
  230.     {$F-}
  231.     mov  [Temp], bx
  232.   end;
  233.   L_Setting := Temp;
  234.   end;
  235. End; {getmastervolume proc}
  236.  
  237. Function GetMixer(In_Out, Channel_Select : Word) : Byte;
  238. { See SetMixer for variable descriptions.
  239.   Basically just returns the volume of the selected mixer.
  240. }
  241. Var Temp : Byte;
  242. Begin
  243.   asm
  244.     mov  cx, In_Out
  245.     mov  dx, Channel_Select
  246.     {$F+}
  247.     call functiontable.mvgetmixerfunction
  248.     {$F-}
  249.     mov  [temp], bl
  250.   end;
  251.   GetMixer := Temp;
  252. end;  {getmixersetting proc}
  253.  
  254. Procedure SetFilter(Filter_Setting : Byte);
  255. { I'm a little unsure about this function call. Here is what the SDK says:
  256.     0% filters out amything higher than 0khz  (mute)
  257.     100% filters out anything lower than 20khz
  258.   It does mute it, but I can't attach a spectrum analyzer to the speaker
  259.   to test the frequency.
  260.   Filter_Setting is the % to filter?
  261. }
  262. Begin
  263.   Asm
  264.     xor  bx, bx
  265.     mov  bl, Filter_Setting
  266.     {$F+}
  267.     call functiontable.mvsetfilterfunction
  268.     {$F-}
  269.   end;
  270. End; {setfilter proc}
  271.  
  272. Function GetFilter : Byte;
  273. { See SetFilter }
  274. Var Temp : Byte;
  275. Begin
  276.   asm
  277.     {$F+}
  278.     call functiontable.mvgetfilterfunction
  279.     {$F-}
  280.     mov [Temp], bl
  281.   end;
  282.   GetFilter := Temp;
  283. End;  {getfilter proc}
  284.  
  285. Procedure Get_Set_RealSound(Get_Set : Boolean;Var On_Off : boolean);
  286. { If Get_Set is true then it is gotten, otherwise it is set.
  287.   If On_Off is true then it is turned on, otherwise turned off.
  288.  
  289.   I added some constants: Get, Set_, On, Off for this procedure. If someone
  290.   wants to make this procedure better, you have my blessing. Yuk.
  291. }
  292. Var ebx, ecx, return : word;
  293. Begin
  294.   if Get_Set then ecx := 0 else ecx := 1;
  295.   if on_off then ebx := 100 else ebx := 0;
  296.   asm
  297.     mov bx, ebx
  298.     mov cx, ecx
  299.     {$F+}
  300.     call functiontable.mvrealsoundswitch
  301.     {$F-}
  302.     mov [return], bx
  303.   end;
  304.   If Get_Set then
  305.     If return = 100 then On_Off := True
  306.     else On_Off := False;
  307. end;   {get_set_realsound}
  308.  
  309. Function GetIRQ : Byte;
  310. { Returns the IRQ of the PAS }
  311. Var Res : Byte;
  312. Begin
  313.   asm
  314.     mov  ax, 0bc04h
  315.     int  2fh
  316.     mov  [res], cl
  317.   end;
  318.   GETIRQ := res;
  319. end;   {getirq proc}
  320.  
  321. Function GetDMA : byte;
  322. { Returns the DMA of the PAS }
  323. Var res: byte;
  324. Begin
  325.   asm
  326.     mov  ax, 0bc04h
  327.     int  2fh
  328.     mov  [res], bl
  329.   end;
  330.   GetDMA := Res;
  331. End;  {getdma proc}
  332.  
  333. Procedure SetVolume(Channel,Setting : Word);
  334. { This procedure will change the setting of a specific channel specified by
  335.   the constants listed under volume channel selection constants.
  336.   Channel is the constant specifying the channel to change
  337.   Setting is the % volume (0-100)
  338. }
  339. Begin
  340.   asm
  341.     mov  bx, Setting
  342.     mov  cx, Channel
  343.     {$F+}
  344.     call functiontable.mvsetvolumefunction
  345.     {$F-}
  346.   end;
  347. End;  {setvolume proc}
  348.  
  349. Function GetVolume(Channel : Word) : Byte;
  350. { See setvolume }
  351. Var Res:Byte;
  352. Begin
  353.   asm
  354.     mov  cx, channel
  355.     {$F+}
  356.     call functiontable.mvgetvolumefunction
  357.     {$F-}
  358.     mov  [res], bl
  359.   end;
  360.   GetVolume := Res;
  361. End; {getvolume func}
  362.  
  363. begin
  364.   if isMVSOUNDInstalled then getfunctiontable
  365.   else begin
  366.          Writeln('MVSOUND.SYS is not installed.');
  367.          Halt(1);
  368.   End;
  369. end.
  370.